define(["ajaxBase"], function (ajaxBase) {
    /*
        节点鼠标Hover 的反应
    */
    let timeHover = (function () {
        let div;
        return function (shareId, userId) {
            if (!div) {
                div = document.createElement("div");
                div.className = "choice-wrapper";
                div.shareId = shareId;
                div.userId = userId;
                div.innerHTML =
                    '<a class="more-choice" title="更多选择">' +
                    '<i class="fa fa-ellipsis-h"></i>' +
                    '<div class="more-choice-frame">' +
                    '<div class="triangle"></div>' +
                    '<div class="triangle-shadow"></div>' +
                    '<div class="more-choice-list" title="关闭">关闭</div>' +
                    '<div class="more-choice-list" title="举报">举报</div>' +
                    '</div>' +
                    '</a>' +
                    '<a class="detail" title="单独观看">' +
                    '<i class="glyphicon glyphicon-fullscreen"></i>' +
                    '</a>';
                //更多选择的点击事件
                div.querySelector(".more-choice").onclick = function (event) {
                    if (div.querySelector(".more-choice-frame").style.display === "" || div.querySelector(".more-choice-frame").style.display === "none") {
                        div.querySelector(".more-choice-frame").style.display = "block";
                        event.stopPropagation();
                    }
                    else {
                        div.querySelector(".more-choice-frame").style.display = "none";
                        event.stopPropagation();
                    }
                };
                //更多选择放置的显示
                div.querySelector(".more-choice-frame").onmouseover = function () {
                    div.querySelector(".more-choice-frame").style.display = "block";
                };
                //详情页的点击事件
                div.querySelector(".detail").onclick = function () {
                    window.open(getRootPath_web() + "/share/oneShare?shareId=" + div.shareId + "&userId=" + div.userId, "_self");
                };
                //关闭按钮的点击事件
                div.querySelectorAll(".more-choice-list")[0].onclick = function () {
                    let node = div.parentNode.parentNode,
                        pareNode = node.parentNode;
                    let data = {
                            shareId: div.shareId,
                            direction: true
                        },
                        url = "/share/hide",
                        method = "POST";
                    layer.msg('你确定要关闭这个分享', {
                        time: 10000,
                        btn: ['是的', '取消']
                    }, function () {
                        ajaxBase(data, url, method, function () {
                            pareNode.removeChild(node);
                        })
                    });

                };
                //举报按钮的点击事件
                div.querySelectorAll(".more-choice-list")[1].onclick = function () {
                    let node = div.parentNode.parentNode;
                    let pareNode = node.parentNode;
                    //重写modelNormal发送框事件
                    let modelAbuse = new ModelNormal();
                    modelAbuse.ajax_send = function () {
                        let data = {
                                shareId: div.shareId,
                                reason: this.pareNode.querySelector(".textarea-share").value
                            },
                            url = "/share/abuse",
                            method = "POST";
                        return ajaxBase(data, url, method);
                    };
                    modelAbuse.setText("分享举报", "举报的原因");
                    modelAbuse.setDisplay("举报");
                }
            }
            div.shareId = shareId;
            div.userId = userId;
            return div;
        };
    })();
    let hover = function () {
        this.nodeList = [];
    };
    hover.prototype.onHover = function (div, shareId, userId) {
        div.onmouseover = function (event) {
            let point = timeHover(shareId, userId),
                pare = this.querySelector(".share-header"),
                previousSibling = pare.querySelector(".time");
            previousSibling.style.display = 'none';
            if (previousSibling.nextSibling !== point)
                pare.insertBefore(point, previousSibling.nextSibling);
            point.style.display = 'inline-block';
        };
        div.onmouseout = function (event) {
            //oNode用于消除onmouseout的bug
            let oNode = event.toElement || event.relatedTarget;
            if (div.contains(oNode)) {
                return;
            }
            let point = timeHover(shareId, userId),
                previousSibling = this.querySelector(".time");
            previousSibling.style.display = 'inline-block';
            point.style.display = 'none';
            point.querySelector(".more-choice-frame").style.display = "none";
        }
    };
    return hover
})